package Eyjafjalla.action;

import com.megacrit.cardcrawl.actions.AbstractGameAction;
import com.megacrit.cardcrawl.actions.common.ExhaustAction;
import com.megacrit.cardcrawl.actions.common.ExhaustSpecificCardAction;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;

import java.util.ArrayList;

public class ExhaustPileAction extends AbstractGameAction {
    public ExhaustPileAction(boolean isDraw,int amount){
        this.isDraw = isDraw;
        this.amount = amount;
    }

    @Override
    public void update() {
        ArrayList<AbstractCard> tmp;
        int count  = this.amount;
        if(isDraw){
            //抽牌堆是逆序
            tmp = new ArrayList<>();
            for(AbstractCard c:AbstractDungeon.player.drawPile.group){
                tmp.add(0,c);
            }
            for(AbstractCard c:tmp){
                if(c.type== AbstractCard.CardType.STATUS){
                    addToTop(new ExhaustSpecificCardAction(c,AbstractDungeon.player.drawPile));
                    count--;
                    if(count<=0)
                        break;
                }
            }
        }
        else {
            tmp = new ArrayList<>(AbstractDungeon.player.discardPile.group);
            for(AbstractCard c:tmp){
                if(c.type== AbstractCard.CardType.STATUS){
                    addToTop(new ExhaustSpecificCardAction(c,AbstractDungeon.player.discardPile));
                    count--;
                    if(count<=0)
                        break;
                }
            }
        }

        this.isDone = true;
    }

    private boolean isDraw;
}
